package com.ym.producer.controller;

import com.ym.producer.service.TestService;
import com.ym.producer.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Timestamp;
import java.time.LocalDateTime;

@Slf4j
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private TestService testService;

    @GetMapping("/async")
    public Result testAsync(){
        //testService.testAsync();
        //这里不能使用get，一旦使用get会变成同步操作
        testService.testAsync2();
        log.info("----------"+Timestamp.valueOf(LocalDateTime.now()));
        return Result.success(200,"success",Timestamp.valueOf(LocalDateTime.now()));
    }

    //利用mq实现异步
    @GetMapping("/mq")
    public Result testMQ(){
        testService.testMQ();
        return Result.success(200,"success",Timestamp.valueOf(LocalDateTime.now()));
    }

}
